<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var $div = $('#div1');
            alert($div.length);
            var $div2 = $('#div2');
            alert($div2.length);
            //通过($div.length) > 0 判断是否选择了元素;



        })
    
    
    </script>
    <title>Document</title>
</head>
<body>
    <div id="div1">div元素</div>

</body>
</html>